<template>
    <div>
<h2>康复显示</h2>
项目名称：<input type="text" v-model="page.name">
<input type="button" value="查询" @click="CHaXun()">


<table class="table">
    <thead>
        <tr>
            <td>项目编号</td>
            <td>项目名称</td>
            <td>服务时长(小时)</td>
            <td>服务人数</td>
            <td>佣金(元)</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <tr v-for="m in data">
            <td>{{ m.id }}</td>
            <td>{{ m.name }}</td>
            <td>{{ m.timeNum }}</td>
            <td>{{ m.num }}</td>
            <td>{{ m.price }}</td>
            <td>{{ m.zhuangTai==1?"正常":"异常"}}</td>
            <td>
                <input type="button" value="逻辑删" @click="Del(m.id)">
                <input type="button" value="修改状态" @click="UpDateZhuangTai(m.zhuangTai)">
                <input type="button" value="修改" @click="UpDate(m.id)">
            </td>
        </tr>
    </tbody>
</table>
<input type="button" value="首页" @click="FanYe(1)">
<input type="button" value="上一页" @click="FanYe(2)">
共{{ pagecount.count }}条，每页{{ page.size }}条，共{{ page.index }}/{{ pagecount.pcount }}页
<select v-model="page.size" @change="SizePage()">
    <option>2</option>
    <option>3</option>
    <option>5</option>
    <option>7</option>
</select>
<input type="button" value="下一页" @click="FanYe(3)">
<input type="button" value="尾页" @click="FanYe(4)">
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter();
onMounted(()=>{
    GetKangFu();
})

const UpDate=(vid:any)=>{
    router.push({path:'/UpDate',query:{id:vid}});
}

const CHaXun=()=>{
    page.value.index=1;
    GetKangFu();
}

const UpDateZhuangTai=(Zt:any)=>{
    if(Zt==1){
        Zt==2;
        GetKangFu();
    }
    if(Zt==2){
        Zt==1;
        GetKangFu();
    }
}

const Del=(vid:any)=>{
    if(!confirm("确认删除吗？")){
        return;
    }
    axios.delete("https://localhost:7182/api/KangFu/DelKangFu",{params:{id:vid}}).then(res=>{
        if(res.data>0){
            alert("删除成功");
            GetKangFu();
        }
        else{
            alert("删除失败");
            return;
        }
    })
}

const SizePage=()=>{
    page.value.index=1;
    GetKangFu();
}

const FanYe=(vid:any)=>{
    if(vid==1){
        page.value.index=1;
        GetKangFu();
    }
    if(vid==2){
        if(page.value.index>1){
            page.value.index-=1;
            GetKangFu();
        }
    }
    if(vid==3){
        if(page.value.index<pagecount.value.pcount){
            page.value.index+=1;
            GetKangFu();
        }
    }
    if(vid==4){
        page.value.index=pagecount.value.pcount;
        GetKangFu();
    }
}

const data=ref([{
    "id": 2,
      "name": "string",
      "timeNum": 0,
      "num": 0,
      "price": 0,
      "zhuangTai": 0
}])

const page=ref({
    index:1,
    size:2,
    name:""
})
const pagecount=ref({
    count:0,
    pcount:0,
})

const GetKangFu=()=>{
    axios.get("https://localhost:7182/api/KangFu/GetKangFu",{params:page.value}).then(res=>{
        data.value=res.data.data;
        pagecount.value.count=res.data.count;
        pagecount.value.pcount=Math.ceil(res.data.count/page.value.size);
    })
}

</script>

<style scoped>

</style>